<template>
  <div>
    <test-input @add="pAdd"/>
    <test-list :text-list="textList" :addItemText="item"/>
  </div>
</template>

<script>
  import TestInput from "./TestInput";
  import TestList from "./TestList";

  export default {
    name: 'TestParent',
    components: { TestList, TestInput },
    data () {
      return {
        textList: [
          {
            id: 1,
            text: '标题1'
          }
        ],
        item: ''
      }
    },
    methods: {
      pAdd (data) {
        console.log(data);
        let len = this.textList.length + 1;
        if (data.text !== '') {
          this.textList.push({
            id: len,
            text: data.text
          });
          this.item = data.text;
        }
      }
    }
  }
</script>

<style scoped>

</style>
